package cn.com.jrr.core.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.jrr.core.model.DataTableResponse;
import cn.com.jrr.core.model.ResponseMessage;
import cn.com.jrr.core.model.Vote;
import cn.com.jrr.core.model.VoteDetail;
import cn.com.jrr.core.service.VoteDetailService;

@Controller
public class VoteFrontAction {
    @Autowired
    private VoteDetailService voteDetailService;
    private VoteDetail voteDetail;
    @Autowired
    private ResponseMessage responseMessage;
    private DataTableResponse<Vote> dt;
    /*
     * 投票访问界面
     */
    @RequestMapping("/front")
    public String front(){
        return "/front/index";
    }
    @RequestMapping("/descipt")
    public String descipt(){
        return "/front/desctipt";
    }
    @ResponseBody
    @RequestMapping("/getDetails")
    public List<VoteDetail> getDetails(Integer voteid){
        List<VoteDetail> data=voteDetailService.getDetails(voteid);
        return data;
    }
    @ResponseBody
    @RequestMapping("/setvote")
    public ResponseMessage setVote(Integer id){
        try{
            VoteDetail vd=voteDetailService.get(id);
            if(vd.getQty()==null){
                vd.setQty(0);
            }
            voteDetailService.setQty(vd.getQty()+1,id);
            responseMessage.setStatus("success");
        }catch(Exception e){
            responseMessage.setStatus("fail");
        }
        return responseMessage;
    }


}
